﻿using System;
using PMngr.Data;

namespace PMngr.Main
{
    public static class Extensions
    {
        public static TU IfNotNull<T, TU>(this T t, Func<T, TU> fn) where T : class
        {
            return t != null ? fn(t) : default(TU);
        }

        public static string FindName(this ItemBase item)
        {
            return item.IfNotNull(i => i.Name);
        }

        public static string FindName(this Unit item)
        {
            return item.IfNotNull(i => i.Name);
        }

        public static DateTime ToDate(this DateTime dt)
        {
            return dt.Date.AddDays(1).AddSeconds(-1);
        }

        public static DateTime FromDate(this DateTime dt)
        {
            return dt.Date;
        }

    }
}
